#include "renderable_manager.h"

RenderableManager* RenderableManager::thisPointer;

RenderableManager::RenderableManager(void) {
  this->pHead = NULL;
  RenderableManager::thisPointer = this;
}

RenderableManager::~RenderableManager(void) {

}

void RenderableManager::Add(RenderableObject *object) {
  if(this->pHead == NULL) {
    pHead = new List;
    this->pHead->object = object;
    this->pHead->pNext = NULL;
  } else {
    List *temp = new List;
    memcpy(temp, pHead, sizeof(List));
    pHead->object = object;
    pHead->pNext = temp;
  }
}


void RenderableManager::Delete(RenderableObject *object) {
  if(pHead == NULL)
    return;
  if(pHead->object == object) {
    if(pHead->pNext == NULL) {
      pHead = NULL;
      return;
    } else {
      pHead = pHead->pNext;
      return;
    }
  }
  List *pre = pHead;
  List *temp = pHead->pNext;
  while(temp != NULL) {
    if(temp->object == object) {
      pre->pNext = temp->pNext;
      pre = NULL;
      temp = NULL;
      return;
    } else {
      pre = temp;
      temp = temp->pNext;
    }
  }
}


void RenderableManager::RemoveAll() {

}


void RenderableManager::Renders() {
  List *temp = pHead;
  while(temp != NULL) {
    temp->object->Render();
    temp = temp->pNext;
  }
}